const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const swaggerUi = require('swagger-ui-express');
const jsdocSwagger = require('express-jsdoc-swagger');
const swaggerOptions = require('./setting/swaggerOptions.js');

const  swaggerSpec = jsdocSwagger(app)(swaggerOptions);
app.use('/api-ui',swaggerUi.serve,swaggerUi.setup(swaggerSpec))
//设置跨域访问//设置跨域访问（设置在所有的请求前面即可）
app.all("*", function (req, res, next) {
	//设置允许跨域的域名，*代表允许任意域名跨域
	res.header("Access-Control-Allow-Origin", "*");
	//允许的header类型
	res.header("Access-Control-Allow-Headers", "content-type");
	//跨域允许的请求方式 
	res.header("Access-Control-Allow-Methods", "DELETE,PUT,POST,GET,OPTIONS");
	if (req.method == 'OPTIONS')
		res.sendStatus(200); //让options尝试请求快速结束
	else
		next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));


// /**
//  * GET /api/authors4444333
//  * @summary This is the summary or description of the endpoint
//  * @param {Song} request.body.required - song info
//  * @return {object} 200 - success response - application/json
//  */
// app.get('/api/authors4444333', (req, res) => res.json({
//   success: true,
// }));

//路由路径引入

app.use(require('./src/controllers/api.js'))
app.use(require('./src/controllers/classroom.js'))
app.use(require('./src/controllers/user.js'))
app.use(require('./src/controllers/menuapi.js'))

app.listen(3001, () => {
  console.log('接口base地址：http://127.0.0.1:3001     接口文档地址:http://localhost:3001/api-docs/#/');
});
